package com.gree.scmservice.controller;

import com.alibaba.fastjson.JSONObject;
import com.gree.common.annotation.Log;
import com.gree.common.entity.ReturnVo;
import com.gree.common.entity.SysLogininfor;
import com.gree.common.entity.SysOperLog;
import com.gree.common.entity.TablePageData;
import com.gree.common.enums.BusinessType;
import com.gree.common.utils.ExcelUtil;
import com.gree.framework.entity.CusUserDetails;
import com.gree.framework.entity.SysUser;
import com.gree.framework.utils.SecurityUtils;
import com.gree.scmservice.dao.LogInfoDao;
import com.gree.scmservice.service.GscmSysOperLogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.nutz.lang.util.NutMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 操作日志
 * Created by 180686 on 2020/11/17 14:48
 */

@RestController
@RequestMapping("/operlog")
@Api(tags = "系统信息:操作日志接口")
public class OperlogController {

    @Autowired
    private GscmSysOperLogService gscmSysOperLogService;

    /**
     * 导出操作日志
     * @param sysOperLog
     * @return
     */
    @GetMapping("/export")
    @ApiOperation(value = "导出操作日志")
    @ApiImplicitParam(name = "sysOperLog", value = "操作日志", dataType = "sysOperLog")
    public void export(SysOperLog sysOperLog, HttpServletResponse response) throws IOException {
        TablePageData<SysOperLog> list = gscmSysOperLogService.selectOperLogList(sysOperLog);
        ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);
        try {
            util.exportExcel(list.getDataList(), "操作日志", response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 分页获取操作日志
     * @param jsonObject
     * @return
     */
    @PostMapping("/getlog")
    @ApiOperation(value = "分页获取操作日志")
    @ApiImplicitParam(name = "logininfor", value = "操作日志", dataType = "SysLogininfor")
    public Object getoperlog(@RequestBody JSONObject jsonObject){
        return ReturnVo.success(gscmSysOperLogService.selectOperLogList(jsonObject));
    }

    /**
     * 删除操作日志
     * @param operIds
     * @return
     */
    @Log(title = "操作日志", businessType = BusinessType.DELETE)
    @DeleteMapping("/{operIds}")
    @ApiOperation(value = "删除操作日志")
    @ApiImplicitParam(name = "operIds", value = "操作日志编号", dataType = "Long[]")
    public Object remove(@PathVariable Long[] operIds){
        int resultNum = gscmSysOperLogService.deleteOperLogByIds(operIds);
        return ReturnVo.toAjax(resultNum);
    }

    /**
     * 清空操作日志
     * @return
     */
    @Log(title = "操作日志", businessType = BusinessType.CLEAN)
    @DeleteMapping("/clean")
    @ApiOperation(value = "清空操作日志")
    public Object clean(){
        gscmSysOperLogService.cleanOperLog();
        return ReturnVo.success();
    }

}
